﻿using log4net;
using log4net.Config;
using Microsoft.Extensions.Hosting;
using System.IO;
using System.Reflection;

namespace AbpOne.ToolKits.Extensions
{
    public static class Log4NetExtensions
    {
        /// <summary>
        /// 配置log4net，然后我们直接返回IHostBuilder对象，便于在Main方法中链式调用
        /// </summary>
        /// <param name="hostBuilder"></param>
        /// <returns></returns>
        public static IHostBuilder UseLog4Net(this IHostBuilder hostBuilder)
        {
            var log4NetRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
            XmlConfigurator.Configure(log4NetRepository, new FileInfo("Resources/log4net.config"));

            return hostBuilder;
        }
    }
}